package com.easyOrder.core.exception;

import com.easyOrder.core.json.JsonExceptionWrapper;
import com.easyOrder.core.json.MappingJacksonJsonViewExd;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import org.springframework.web.bind.annotation.ControllerAdvice;


//@ControllerAdvice
public class SimpleExceptionHandler extends ExceptionHandlerExceptionResolver {

	private MappingJacksonJsonViewExd jsonView = new MappingJacksonJsonViewExd();

	@ExceptionHandler(Throwable.class)
	public @ResponseBody Object processException(HttpServletRequest request,
                                                 HttpServletResponse response, Exception e) {
		response.setStatus(200);
		return new ModelAndView(jsonView, "error", new JsonExceptionWrapper(e));
	}
}
